//
//  XMSetViewController.m
//  XMJJ_zml
//
//  Created by apple on 2025/5/13.
//

#import "XMSetViewController.h"
#import "XMSetView.h"

#import "XMAccountSafeViewController.h"
#import "XMNotifiSetViewController.h"
#import "XMPrivacySetViewController.h"
#import "XMFeedbackViewController.h"
#import "XMMyAddressViewController.h"

#import "XMNetwork+mine.h"

@interface XMSetViewController ()

@end

@implementation XMSetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatUI];
}

- (void)creatUI {
    XMSetView *setView = [[XMSetView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:setView];
    
    XMWeakSelf;
    setView.itemSelectBlock = ^(NSInteger section, NSInteger row) {
        [weakSelf itemSelectWithSection:section row:row];
    };
}

- (void)itemSelectWithSection:(NSInteger)section row:(NSInteger)row {
    if (section == 0) {
        switch (row) {
            case 0: {
                XMAccountSafeViewController *accountSafeVC = [[XMAccountSafeViewController alloc] init];
                accountSafeVC.userInfoModel = self.userInfoModel;
                [self.navigationController pushViewController:accountSafeVC animated:YES];
            }
                break;
            case 1: {
                XMNotifiSetViewController *notifiSetVC = [[XMNotifiSetViewController alloc] init];
                [self.navigationController pushViewController:notifiSetVC animated:YES];
            }
                break;
            case 2: {    //
                XMPrivacySetViewController *privacySetVC = [[XMPrivacySetViewController alloc] init];
                [self.navigationController pushViewController:privacySetVC animated:YES];
            }
                break;
                
            default:
                break;
        }
    }
    else {
        switch (row) {
            case 0: {  //地址
                XMMyAddressViewController *addressVC = [[XMMyAddressViewController alloc] init];
                [self.navigationController pushViewController:addressVC animated:YES];
            }
                break;
            case 1: {
            }
                break;
            case 2: {   //反馈
                XMFeedbackViewController *feedbackVC = [[XMFeedbackViewController alloc] init];
                [self.navigationController pushViewController:feedbackVC animated:YES];
            }
                break;
            case 4: {
                XMWeakSelf;
                [_Network logoutSuccess:^(id  _Nonnull responseObject) {
                    [[XMUserManager shareInstance] removeUser];
//                    [[XMUserManager shareInstance] removeToken];
                    [weakSelf.navigationController popToRootViewControllerAnimated:NO];
                    self.tabBarController.selectedIndex = 0;
                } failure:^(NSError * _Nonnull error) {
                    
                }];
            }
                break;
            default:
                break;
        }
    }
}

- (void)logout {
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
